package com.car.demo.impl;

import com.car.demo.dao.CarDao;
import com.car.demo.model.CarEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Component;

import java.util.List;
@Component("CarDao")
public class CarDaoImpl implements CarDao {
    static Logger logger = LoggerFactory.getLogger(CarDaoImpl.class);

    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public List<CarEntity> getAllData() {
        return mongoTemplate.findAll(CarEntity.class);
    }

    @Override
    public List<CarEntity> getByName(String name) {
        return mongoTemplate.find(new Query(Criteria.where("name").is(name)),CarEntity.class);
    }
}
